home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / table / ch_tbseq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-28  |  4.1 KB  |  136 lines

  1. /*
  2.  *     MULTI-CHANNEL MEMO DISTRIBUTION FACILITY  (MMDF)
  3.  *     
  4.  *
  5.  *     Copyright (C) 1979,1980,1981  University of Delaware
  6.  *     
  7.  *     Department of Electrical Engineering
  8.  *     University of Delaware
  9.  *     Newark, Delaware  19711
  10.  *
  11.  *     Phone:  (302) 738-1163
  12.  *     
  13.  *     
  14.  *     This program module was developed as part of the University
  15.  *     of Delaware's Multi-Channel Memo Distribution Facility (MMDF).
  16.  *     
  17.  *     Acquisition, use, and distribution of this module and its listings
  18.  *     are subject restricted to the terms of a license agreement.
  19.  *     Documents describing systems using this module must cite its source.
  20.  *
  21.  *     The above statements must be retained with all copies of this
  22.  *     program and may not be removed without the consent of the
  23.  *     University of Delaware.
  24.  *     
  25.  *
  26.  *     version  -1    David H. Crocker    March   1979
  27.  *     version   0    David H. Crocker    April   1980
  28.  *     version  v7    David H. Crocker    May     1981
  29.  *     version   1    David H. Crocker    October 1981
  30.  *
  31.  */
  32.  
  33. /*  Sep 81  Dave Crocker      added ch_tclose & ch_tfree, to allow
  34.  *                            handling file descriptor overflow
  35.  *  May 82  Dave Crocker      add ch_tread, to focus input
  36.  *  Jun 82  Dave Crocker      split ch_tio off from ch_table
  37.  *                            if local name, use lname, for proper case
  38.  *  May 84  G. B. Reilly      added in domain support
  39.  */
  40.  
  41. #include "util.h"
  42. #include "mmdf.h"
  43. #include "ch.h"              /* has table state strcture def       */
  44. #include "dm.h"              /* has domain info */
  45.  
  46. extern Chan **ch_tbsrch;
  47. extern LLog *logptr;
  48. extern char *ch_dflnam;
  49.  
  50. extern Domain **dm_list;
  51.  
  52.  
  53. /* ******************  FIND HOST NAME IN ANY TABLE  ****************** */
  54.  
  55. Chan   *
  56.     ch_h2chan (hostr, pos) /* which chan name table is host in?  */
  57. register char  *hostr;          /* name of host                       */
  58. int    pos;              /* position */
  59. {
  60.     register Chan  **chanptr;
  61.     char adrstr[LINESIZE];
  62.  
  63. /*  the list of channel name tables is first searched.  If a hit is found
  64.  *  in the table for the local channel, OK is returned to indicate a local
  65.  *  reference.
  66.  */
  67.  
  68.     for (chanptr = ch_tbsrch; *chanptr != 0; chanptr++)
  69.     {
  70.     if (tb_k2val ((*chanptr) -> ch_table, TRUE, hostr, adrstr) == OK)
  71.     {              /* the hostname IS in this table      */
  72.         if (lexequ (ch_dflnam, (*chanptr) -> ch_name))
  73.         {
  74.         return ((Chan *) OK); /* local reference                */
  75.         }
  76.         return (*chanptr);    /* let caller know which chan         */
  77.     }
  78.     }
  79.  
  80.     return ((Chan *) NOTOK);      /* host not listed anywhere           */
  81. }
  82. /*  ***********  GIVEN Subdomain, FIND Domain  ***************** */
  83.  
  84.  
  85.  
  86. Domain *
  87.     dm_s2dom (subdomain, official, dmbuf)
  88. char    *subdomain;        /* name of subdomain to look up */
  89. char    *official;        /* where to stuff official name */
  90. char    *dmbuf;            /* Domain route buffer */
  91. {
  92.     char *argv[DM_NFIELD];
  93.     char val[LINESIZE];
  94.     register Domain **dmnptr;
  95.  
  96.     for (dmnptr = dm_list; *dmnptr != 0; dmnptr++)
  97.     {
  98.     if (tb_k2val ((*dmnptr) -> dm_table, TRUE, subdomain, val) == OK) {
  99.         (void) strcpy(dmbuf, val);
  100.         str2arg(val, DM_NFIELD, argv, 0);
  101.         (void) strcpy(official, argv[0]);
  102.             return (*dmnptr);
  103.     }
  104.     }
  105.  
  106.     (void) strcpy (official, subdomain); /* to have something in the buffer */
  107.     (void) strcpy (dmbuf, subdomain);    /* to have something in the buffer */
  108.     return ((Domain *) NOTOK);
  109. }
  110.  
  111. /*  *******  FIND VALUE (address), GIVEN ITS KEY (hostname)  ********* */
  112.  
  113. tb_k2val (table, first, name, buf) /* use key and return value */
  114. register Table  *table;
  115. int     first;                    /* start at beginning of list?        */
  116. char   *buf;              /* put value int this buffer          */
  117. register char  *name;          /* name of ch "member" / key          */
  118. {
  119.     char    host[LINESIZE];
  120.  
  121.     if (!tb_open (table, first))
  122.     return (NOTOK);          /* not opened                         */
  123.  
  124.     while (tb_read (table, host, buf))
  125.     {                  /* cycle through keys                 */
  126.     if (lexequ (name, host))  /* does key match search name?        */
  127.     {
  128.         compress (buf, buf);  /* get rid of extra white space       */
  129.         return (OK);
  130.     }
  131.     }
  132.  
  133.     (void) strcpy (buf, "(ERROR)");
  134.     return (NOTOK);
  135. }
  136.